/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.biblio.model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.*;

/**
 *
 * @author morgan
 */
@Entity

//les requetes
@NamedQuery(name = User.FIND_BY_USERNAME, 
        query = "SELECT u FROM User u WHERE u.username=:username")

@Table(name="users")
public class User implements Serializable 
{
    public static final String FIND_BY_USERNAME = "User.FindByUsername";
    public static final String FIND_ALL_FRIENDS = "User.FindAllFriends";
    
    @Id    
    @Column(name="username")
    private String username;
    
    @Column(name="password")
    private String password;
    
    @Transient
    private String confirmPassword;
    
    @OneToMany(mappedBy = "proprietaire")
    private List<Status> statuses;
    
    @ManyToMany
    private List<User> friends;
    
    @ManyToMany
    private List<Status> likedStatus;

    public List<Status> getLikedStatus() {
        if (likedStatus==null)
            likedStatus = new LinkedList<>();
        return likedStatus;
    }

    public void setLikedStatus(List<Status> likedStatus) {
        this.likedStatus = likedStatus;
    }

    public List<Status> getStatuses() {
        return statuses;
    }

    public void setStatuses(List<Status> statuses) {
        this.statuses = statuses;
    }

    public List<User> getFriends() {        
        return friends;
    }   

    public void setFriends(List<User> friends) {
        this.friends = friends;
    }
    
    public User() 
    {
    }
    
    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public String toString() {
        return "User{" + "username=" + username + ", password=" + password + ", confirmPassword=" + confirmPassword + ", statuts=" + statuses + '}';
    }
}
